<template>
  <arp1 @query="query"/>
</template>

<script>
  import Arp1 from "../../pageTemplate/arp1";
  import {mapState,mapActions} from 'vuex';

  export default {
    components: {Arp1},
    data() {
      return {}
    },
    mounted(){
      this.fetchData();
    },
    computed:{
      ...mapState({
        gameList: state => state.app.gameList,
      })
    },
    watch: {
      // 如果路由有变化，会再次执行该方法
      '$route': 'fetchData',
      '$store.state.app.gameList': 'fetchData'
    },
    methods :{
      ...mapActions([
        'realtime_tableData','realtime_cardData'
      ]),
      fetchData:function () {
        let game = this.$route.params.id;
        let list = JSON.parse(localStorage.getItem("gameList"))||this.gameList;
        let set = list.find((item)=>{
          return item.project_abb===game;
        });
        const now = new Date();
        let edate = now.Format("yyyy-MM-dd");
        let sdate = new Date(now.getTime() - 3600 * 1000 * 24 * 30).Format("yyyy-MM-dd");
        let p = {set:set,startdate:sdate,enddate:edate};
        if(set) {
          this.realtime_tableData(p);
          this.realtime_cardData(p);
        }
      },
      query:function (param) {
        let game = this.$route.params.id;
        let list = JSON.parse(localStorage.getItem("gameList"))||this.$store.state.app.gameList;
        let set = list.find((item)=>{
          return item.project_abb===game;
        });
        param.set = set;
        this.realtime_tableData(param);
      }
    }
  }

</script>

